/**
 * Author: Dmitry Ustimov
 * Date: 5/31/13
 * Time: 8:14 PM
 */

package com.gmail.dmitryustimov.ms.java7.mediator.classic.work.demo.col10event10;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class Mediator implements Colleague {

    private String name;
    private List<Colleague> colleagueList = new ArrayList<>();
    private BigDecimal sum = BigDecimal.valueOf(0);

    public Mediator(String name) {
        this.name = name;
    }

    public void addColleague(AbstractColleague colleague) {
        colleagueList.add(colleague);
    }

    @Override
    public void process(Event event, Colleague colleague) {
        for (Colleague c: colleagueList) {
            if (c != colleague) {
                if (event instanceof Event1) {
                    process(((Event1)event), c, colleague);
                }
                if (event instanceof Event2) {
                    process(((Event2)event), c, colleague);
                }
                if (event instanceof Event3) {
                    process(((Event3)event), c, colleague);
                }
                if (event instanceof Event4) {
                    process(((Event4)event), c, colleague);
                }
                if (event instanceof Event5) {
                    process(((Event5)event), c, colleague);
                }
                if (event instanceof Event6) {
                    process(((Event6)event), c, colleague);
                }
                if (event instanceof Event7) {
                    process(((Event7)event), c, colleague);
                }
                if (event instanceof Event8) {
                    process(((Event8)event), c, colleague);
                }
                if (event instanceof Event9) {
                    process(((Event9)event), c, colleague);
                }
                if (event instanceof Event10) {
                    process(((Event10)event), c, colleague);
                }
            }
        }
    }

    private void process(Event1 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event2 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event3 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event4 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event5 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event6 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event7 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event8 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event9 event, Colleague to, Colleague from) {
        to.process(event, from);
    }

    private void process(Event10 event, Colleague to, Colleague from) {
        to.process(event, from);
    }
}
